/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: LazySimpleSingleton.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/2/28 上午11:36
 * LastModified: 2020/02/28 11:36:28
 */

package com.qolome.knowledge.design.pattern.singleton.lazy;

import java.util.Objects;

/**
 * @author Qolome
 * @version V1.0
 * @Description 懒汉双重检查单例
 * 优点: ,性能提高,线程安全
 * 缺点:可读性差
 * @date 2020年 02月28日 11:36:23
 */
public class LazyDoubleCheckSingleton {

    private volatile static LazyDoubleCheckSingleton instance;
    private LazyDoubleCheckSingleton(){};

    public  static LazyDoubleCheckSingleton getInstance(){

       if(Objects.nonNull(instance)){
                synchronized (LazyDoubleCheckSingleton.class){
                    if(Objects.nonNull(instance)){
                        instance = new LazyDoubleCheckSingleton();
                        //防止指令重排序 增加 volatile
                    }
             }
        }
        return instance;
    }


}
